package acwing._2LanQiao._1Recursion;

import java.util.Scanner;

/**
 * @Project : ProgrammingExercises
 * @Package : ACWing._2LanQiao._1_1Recursion
 * @File : Q1209.java
 * @Author : WangRuoyu
 * @Date : 2023/3/13 9:27
 */

public class Q1209 {
    static int n;
    static boolean[] remove = new boolean[10];
    static int res = 0;

    static boolean check(int a, int c) {
        long b = (long) c * (n - a);
        boolean[] checks = new boolean[10];
        System.arraycopy(remove, 1, checks, 1, 9);
        while (b != 0) {
            if (checks[(int) (b % 10)] || b % 10 == 0) {
                return false;
            }
            checks[(int) (b % 10)] = true;
            b /= 10;
        }

        for (int i = 1; i <= 9; ++i) {
            if (!checks[i]) {
                return false;
            }
        }
        return true;
    }

    public static void dfs_c(int a, int c) {
        if (c != 0 && check(a, c)) {
            res++;
        }
        for (int i = 1; i <= 9; ++i) {
            if (!remove[i]) {
                remove[i] = true;
                dfs_c(a, c * 10 + i);
                remove[i] = false;
            }
        }
    }

    public static void dfs_a(int a) {
        if (a >= n) {
            return;
        }
        if (a != 0) {
            dfs_c(a, 0);
        }

        for (int i = 1; i <= 9; ++i) {
            if (!remove[i]) {
                remove[i] = true;
                dfs_a(a * 10 + i);
                remove[i] = false;
            }
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        remove[0] = true;
        dfs_a(0);
        System.out.println(res);
    }
}
